<?php
/**
 * Created by PhpStorm.
 * User: HS032
 * Date: 2020/8/22
 * Time: 10:22
 */

namespace ticket\modules\backend\controllers;

use ticket\libs\Tools;
use ticket\modules\backend\models\TicketQuotaRule;
use Yii;

/*** 门票限购规则
 * Class TicketQuotaController
 * @package ticket\modules\backend\controllers
 */
class TicketQuotaController extends BasicController
{

    public function actionQuotaInfo()
    {
        if (Yii::$app->request->isPost){
            $post = Yii::$app->request->post();
            $tid = isset($post['tid'])?$post['tid']:'';
            if (empty($tid)){
                return Tools::showRes(99,'参数有误');
            }

            $quotaModel = new TicketQuotaRule();

            $ticketQuotaInfo = $quotaModel->getQuotaInfo($tid);

            return Tools::showRes(0,'success',[
                'ticketQuotaInfo' => $ticketQuotaInfo,
            ]);


        }

    }


    /*** 添加、修改门票限购规则
     * @return false|string
     */
    public function actionSetQuotaRule()
    {
        if (Yii::$app->request->isPost){
            $post = Yii::$app->request->post();
            $quotaModel = new TicketQuotaRule();
            if (!$quotaModel->addQuotaRule($post)){
                if ($quotaModel->hasErrors()){
                    return Tools::showRes(10044,$quotaModel->getErrors());
                }else{
                    return Tools::showRes(10045,'规则添加失败');
                }
            }
            return Tools::showRes(0,'规则添加成功');
        }
    }






}